<?php
namespace app\admin\controller;

use app\common\builder\ZBuilder;
use app\admin\model\Recommend as RecommendModel;
use think\Image;
use think\File;
use think\facade\Hook;
use think\Db;
use think\facade\Env;

class Recommend extends Admin
{
    public function index()
    {
        // 查询
        $map = $this->getMap();
         // 数据列表
         $recommendModel = new RecommendModel();
         $data_list = $recommendModel->getList($map);
 
         foreach($data_list as $k=>$row){
             $data_list[$k]['wx_qrcode'] = getImgUrl($row['wx_qrcode']);
             $data_list[$k]['images'] = getImgUrl($row['images']);
         }
 
         $wxappList = Db::name('admin_wxapp')->field('id,title')->select();
         foreach($wxappList as $k=>$row){
             $wxlist[$row['id']] = $row['title'];
         }
         $fields = [
             ['hidden','id'],
             ['text','title','小程序标题'],
             ['select','wxapp_id','选择小程序','',$wxlist],
             ['image','wx_qrcode','小程序码'],
             ['image','images','推广图片'],
             ['ueditor','desc','推广文案'],
             ['hidden','addtime',time(),time()],
             ['radio','status','状态','', ['禁用', '启用'], 1],
         ];
         return ZBuilder::make('table')
         ->setSearch(['q.title' => '标题','w.title' => '所属小程序']) // 设置搜索框
         ->setPageTitle('二维码管理')
         //->addTopButton('add') // 添加顶部按钮
         ->autoAdd($fields,'','','addtime') // 添加新增按钮
         ->autoEdit($fields,'','','mdtime') // 添加编辑按钮
         ->addColumns([ // 批量添加数据列
             ['id', 'ID'],
             ['title', '小程序标题'],
             ['wtitle', '所属小程序'],
             ['wx_qrcode', '二维码图片',parse_attr(Db::name('admin_config')->where('name', 'upload_driver')->value('options'))],
             ['images', '推广图片',parse_attr(Db::name('admin_config')->where('name', 'upload_driver')->value('options'))],
             ['addtime', '添加时间', 'datetime'],
             ['status', '状态', 'switch'],
             ['right_button', '操作', 'btn']
         ])
         ->addTopButtons('enable,disable,delete') // 批量添加顶部按钮
         ->addRightButtons('delete') // 批量添加右侧按钮
         ->setRowList($data_list) // 设置表格数据
         ->fetch(); // 渲染模板
    }
}